//
//  DDChatMessageViewController.m
//  DingDongZP
//
//  Created by 王威 on 16/3/18.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDChatMessageViewController.h"
#import "DDChatHeaderReusableView.h"
#import "DDMessageSettingViewController.h"
#import "DDResumeCell.h"
#import "DDContactRequestMessage.h"
#import "DDInterviewReply.h"   // 邀约面试title消息
#import "DDInterviewMessage.h"  //  邀约面试的相关信息
#import "DDContactRequestCell.h"
#import "DDContactReplyCell.h"
#import "DDContactAcceptCell.h"
#import "DDContactAccept_Receive.h"
#import "DDContactRefusedCell.h"
#import "DDContactRequestCache.h"    //缓存数据，检查是否已经已经申请过交换信息
#import <SVProgressHUD/SVProgressHUD.h>
#import <AddressBook/AddressBook.h>
#import <RongIMLib/RongIMLib.h>
#import <RongCallKit/RCCall.h>
#import <RongCallKit/RCCallDetailMessageCell.h>
#import "DDCommunicatedStore.h"
#import "DDLoginUserManager.h"
#import "DDJobfindersBaseModel.h"
#import "DDWorkDetailViewController.h"
#import "DDChangePhoneAlert.h"
#import "DDInvitedViewController.h"   // 面试邀请
/**
 *  邀约面试相关 自定义消息Cell
 *
 */
#import "DDInterviewTitleCell.h"
#import "DDInterviewSendCell.h"
#import "DDInterviewReceiveCell.h"
#import "DDInterviewReplayCell.h"

#import "DDIntervitedService.h"  // 牛人端 回复面试邀请结果给服务器
#import "DDBossOnlineInterviewAlert.h"  //Boss用户查询账户余额

#define CollectionHeaderIndentifier @"CollectionHeaderIndentifier"

@interface DDChatMessageViewController ()
<UICollectionViewDelegateFlowLayout,
UICollectionViewDelegate,
UICollectionViewDataSource,
DDContactDelegate,DDRequestInterviewDelegate>
{
    BOOL _showTips; //是否显示直聘技巧
    NSUserDefaults *didContactUserdefaults; //是否跟对方聊过
}
@property (strong, nonatomic)DDChatHeaderReusableView *headerView;
@property (strong, nonatomic)DDJobsDetail *bossDetail;

@property (strong, nonatomic)NSString *presentUserID;  //当前用户ID
@property (strong, nonatomic)NSUserDefaults *savaJobIdUserDefaults;  //保存JodId
@property (assign, nonatomic)CGSize size;
@property (strong, nonatomic)DDChangePhoneAlert *popChangePhoneAlert;

@property (strong, nonatomic)DDIntervitedService *intervitedService;

@end

@implementation DDChatMessageViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.intervitedService = [[DDIntervitedService alloc]init];
    /**
     *  缓存聊天对象的名字
     */
    if (self.title) {
        NSUserDefaults *theOppositeSide = [NSUserDefaults standardUserDefaults];
        [theOppositeSide setObject:self.title forKey:@"theOppositeSide"];
        [theOppositeSide synchronize];
    }
    //  在聊天扩展面板中 去掉发送位置、语音通话、视频通话的选项
    [self.chatSessionInputBarControl.pluginBoardView removeItemAtIndex:4];  // 因为视频通话的选项 排列在第五个
    [self.chatSessionInputBarControl.pluginBoardView removeItemAtIndex:3];  // 因为语音通话的选项 排列在第四个
    [self.chatSessionInputBarControl.pluginBoardView removeItemAtIndex:2];  // 因为位置的选项 排列在第三个
    
    /**
     *  设置视频通话的分辨率
     */
    RCCallClient *callClient = [RCCallClient sharedRCCallClient];
    [callClient setVideoProfile:RC_VIDEO_PROFILE_480P];
    
    
    didContactUserdefaults = [NSUserDefaults standardUserDefaults];
    
    [self.chatSessionInputBarControl.additionalButton addTarget:self
                                                         action:@selector(setFrames) forControlEvents:UIControlEventTouchUpInside];
    self.conversationMessageCollectionView.delegate = self;
    self.conversationMessageCollectionView.dataSource = self;
    self.displayUserNameInCell = false;
    
    [self.conversationMessageCollectionView registerClass:[DDChatHeaderReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CollectionHeaderIndentifier];
    
    /**
     交换微信/电话之前的提示弹窗
     */
    self.popChangePhoneAlert = [[DDChangePhoneAlert alloc]initWithCreatDDChangePhoneAlertframe:self.view.frame];
    [self.view bringSubviewToFront:self.popChangePhoneAlert];
    
    /**
     *  通知  点击了交换微信/电话之前的提示弹窗的确定
     */
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changePhone) name:@"DDchangePhone" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeWeiXin) name:@"DDchangeWeiXin" object:nil];
    
    /**
     *  通知  点击了在线面试/邀约面试之前的提示弹窗的确定
     */
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onlineVideoInterview) name:@"DDOnlineVideoInterview" object:nil]; // 在线面试
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(invitationInterview) name:@"DDInvitationInterview" object:nil]; // 邀约面试

    
    //注册自定义
    [self registerClass:[RCUnknownMessageCell class] forCellWithReuseIdentifier:@"unknown"];  //未知消息类Cell
//    [self registerClass:[DDContactRequestCell class] forCellWithReuseIdentifier:@"DDRequest"];  //当点击交换电话或者交换微信的时候，己方显示“请求电话/微信已发送”
//    [self registerClass:[DDContactReplyCell class] forCellWithReuseIdentifier:@"DDReply"]; //当点击交换电话或者交换微信的时候，对方显示弹出交换微信或者电话的窗口
//    
//    /**
//     *  下面三个是点击交换微信/电话   的同意/拒绝事件  显示的Cell
//     */
//    [self registerClass:[DDContactAcceptCell class] forCellWithReuseIdentifier:@"DDAccept"];  //接受交换微信或者电话（发送方）
//    [self registerClass:[DDContactAccept_Receive class] forCellWithReuseIdentifier:@"DDAccept_Receive"];//接受交换微信或者电话（接收方）
//    [self registerClass:[DDContactRefusedCell class] forCellWithReuseIdentifier:@"DDRefused"];  //拒绝交换微信或者电话
    
    /**
     *  邀约面试相关
     */
    [self registerClass:[DDInterviewTitleCell class] forCellWithReuseIdentifier:@"DDInterviewTitle"];  //发送面试邀请的时候第一条自定义消息
    [self registerClass:[DDInterviewSendCell class] forCellWithReuseIdentifier:@"DDInterviewSendCell"];  //发送面试邀请的卡片
    [self registerClass:[DDInterviewReceiveCell class] forCellWithReuseIdentifier:@"DDInterviewReceiveCell"];  //发送面试邀请的卡片
    [self registerClass:[DDInterviewReplayCell class] forCellWithReuseIdentifier:@"DDInterviewReplayCell"];  //回复面试邀请
    
    [self setRightBarButtonItemWithWhite];
    [self setChat];
    
    /**
     *  暂时先取消交换电话\交换微信   Boss端改为显示  在线面试\邀约面试    牛人端改为在线面试
     */
//    [self initChangeView];
    
    /**
     *  在线面试\邀约面试
     */
    [self initOnlineVideoInterviewAndInvitationInterview];
    
    
    [RCIM sharedRCIM];
    
    /**
     * 是否跟对方联系过  当联系过了，就不显示。没联系过就显示，所以要取反
     */
    //  self.presentUserID 获取本人的userID
    NSString *typestring;
    if ([DDClientInfoManager clientType] == DDClientTypeBoss) {
        typestring = @"employer";
    }
    else {
        typestring = @"jobfinder";
    }
    self.presentUserID = [NSString stringWithFormat:@"%@_%@",[DDLoginUserManager userID], typestring];
    
    _showTips = ![didContactUserdefaults boolForKey:[NSString stringWithFormat:@"%@To%@",self.presentUserID,self.targetId]];
    
    
    if (!_jobid) {
        
        _savaJobIdUserDefaults = [NSUserDefaults standardUserDefaults];
        _jobid = [_savaJobIdUserDefaults objectForKey:[NSString stringWithFormat:@"%@To%@_JobId",self.targetId,self.presentUserID]];
    }
    
    NSString *userPhoto = [DDLoginUserManager ddportrait];
    userPhoto = [DDAPIGenerate imageURLWithPath:userPhoto];
    /**
     *  携带当前用户信息
     */
    [RCIM sharedRCIM].currentUserInfo = [[RCUserInfo alloc]initWithUserId:self.presentUserID name:[DDLoginUserManager accountNamefirst] portrait:userPhoto];
    [RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
    
    [self getJobDetailInfo];
    [self getChatTargetInfo];
    [self setupNav];
}

-(void) setupNav {
    
    self.navigationController.navigationBar.translucent = false;
    self.navigationController.navigationBar.barTintColor = COLOR_NAVIGATIONBAR;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:16]}];
    
}

-(UIBarButtonItem *)customBackItemWithTarget:(id)target action:(SEL)action {
    
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navBack.png"] style:UIBarButtonItemStyleDone target:self action:@selector(doBack)];
    
    return  btn;
    
}


-(void)doBack {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.rdv_tabBarController setTabBarHidden:true animated:true];
    
    _savaJobIdUserDefaults = [NSUserDefaults standardUserDefaults];
    [_savaJobIdUserDefaults setObject:[NSString stringWithFormat:@"%@",self.jobid] forKey:[NSString stringWithFormat:@"%@To%@_JobId",self.targetId,self.presentUserID]];
    [_savaJobIdUserDefaults synchronize];
    
    NSDictionary *command = @{@"target":self.presentUserID,@"jobid": self.jobid};
    NSData *commandData = [NSJSONSerialization dataWithJSONObject:command options:0 error:nil];
    NSString *commandjson = [[NSString alloc] initWithData:commandData encoding:NSUTF8StringEncoding];
    RCCommandMessage *commandmsg = [RCCommandMessage messageWithName:@"setjob" data:commandjson];
    [self sendMessage:commandmsg pushContent:nil];
    
}

- (void)initChangeView
{
    UIView *changeView = [[UIView alloc] init];
    changeView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:changeView];
    [self.view bringSubviewToFront:changeView];
    
    //change button
    UIButton *changePhoneButton = [UIButton setDetailsBtn:@"  交换电话" picName:@"交换电话UI" btnBackColor:COLOR_WHITE titleColor:[UIColor colorWithRed:1.000 green:0.506 blue:0.145 alpha:1.000]];
    
    [changePhoneButton addTarget:self action:@selector(actionChangePhoneButton:) forControlEvents:UIControlEventTouchUpInside];
    [changeView addSubview:changePhoneButton];
    
    UIButton *changeWeChatButton = [UIButton setDetailsBtn:@"  交换微信" picName:@"交换微信UI" btnBackColor:COLOR_WHITE titleColor:[UIColor colorWithRed:0.310 green:0.773 blue:0.161 alpha:1.000]];
    [changeWeChatButton addTarget:self action:@selector(actionChangeWechat:) forControlEvents:UIControlEventTouchUpInside];
    
    [changeView addSubview:changeWeChatButton];
    
    WEAKSELF
    [changeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.conversationMessageCollectionView);
        make.left.equalTo(weakSelf.conversationMessageCollectionView);
        make.width.equalTo(weakSelf.conversationMessageCollectionView);
        make.height.mas_equalTo(@44);
    }];
    
    [changePhoneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(changeView);
        make.top.equalTo(changeView);
        make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width / 2);
        make.height.equalTo(changeView);
    }];
    
    [changeWeChatButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(changePhoneButton.mas_right);
        make.top.equalTo(changePhoneButton);
        make.size.equalTo(changePhoneButton);
    }];
    
    UIImageView *dashedImageView = [[UIImageView alloc]init];
    dashedImageView = [self setupDivideLine_V:30];
    [changeView addSubview:dashedImageView];
    [dashedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(@(1));
        make.height.equalTo(@(30));
        make.centerX.equalTo(changeView);
        make.centerY.equalTo(changeView);
    }];
    
}

/**
 *  视频面试\邀约面试
 */
- (void)initOnlineVideoInterviewAndInvitationInterview
{
   
    UIView *interview = [[UIView alloc] init];
    interview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:interview];
    [self.view bringSubviewToFront:interview];
    
    UIButton *videoInterviewButton = [UIButton setDetailsBtn:@"  在线面试" picName:@"视频面试" btnBackColor:COLOR_WHITE titleColor:[UIColor colorWithRed:1.000 green:0.506 blue:0.145 alpha:1.000]];
    [videoInterviewButton addTarget:self action:@selector(actionOnlineVideoInterview:) forControlEvents:UIControlEventTouchUpInside];
    [interview addSubview:videoInterviewButton];
 
    UIButton *invitationInterviewiButton;
    if ([DDClientInfoManager clientType] == DDClientTypeBoss){
     
        invitationInterviewiButton = [UIButton setDetailsBtn:@"  邀约面试" picName:@"邀约面试" btnBackColor:COLOR_WHITE titleColor:[UIColor colorWithRed:0.196 green:0.655 blue:0.792 alpha:1.000]];
        [invitationInterviewiButton addTarget:self action:@selector(actionInvitationInterview:) forControlEvents:UIControlEventTouchUpInside];
        [interview addSubview:invitationInterviewiButton];
    }
    
    WEAKSELF
    [interview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.conversationMessageCollectionView);
        make.left.equalTo(weakSelf.conversationMessageCollectionView);
        make.width.equalTo(weakSelf.conversationMessageCollectionView);
        make.height.mas_equalTo(@44);
    }];
    
    if ([DDClientInfoManager clientType] == DDClientTypeBoss){
        
        [videoInterviewButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(interview);
            make.top.equalTo(interview);
            make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width / 2);
            make.height.equalTo(interview);
        }];
        
        [invitationInterviewiButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(videoInterviewButton.mas_right);
            make.top.equalTo(videoInterviewButton);
            make.size.equalTo(videoInterviewButton);
        }];
        
        UIImageView *dashedImageView = [[UIImageView alloc]init];
        dashedImageView = [self setupDivideLine_V:30];
        [interview addSubview:dashedImageView];
        [dashedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.equalTo(@(1));
            make.height.equalTo(@(30));
            make.centerX.equalTo(interview);
            make.centerY.equalTo(interview);
        }];
        
    }else{
        
    [videoInterviewButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.width.height.equalTo(interview);
    }];
    
    }
}


-(void)setFrames
{
    //self.pluginBoardView.frame = CGRectMake(0, self.view.height - 78.f, self.pluginBoardView.frame.size.width,78.f);
}

//  显示卡片
- (void)getJobDetailInfo
{
    if (_jobid) {
        NSString *requestUrlString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_loggedin_view_job"];
        NSDictionary *params = @{@"job_id": _jobid};
        
        WEAKSELF
        [[DDNetWorkManager shareManager] POST:requestUrlString parameters:params success:^(id responseObject) {
            
            //  获得一个工作详情
            NSDictionary *data = responseObject[@"data"];
            if (data) {
                
                //工作详情保存
                DDJobsDetail *job = [DDJobsDetail yy_modelWithDictionary:data];
                weakSelf.bossDetail = job;
                
                if (!self.bossDetail) {
                    self.size =  CGSizeMake(self.view.width, 44+15+30);  // 没有聊天卡片的时候
                }else{
                    if (_showTips) {
                        self.size =  CGSizeMake(self.view.width, 270);
                    }
                    else {
                        self.size  = CGSizeMake(self.view.width, 220);
                    }
                }
                
                [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                    
                    [weakSelf.conversationMessageCollectionView reloadData];
                }];
                //  如果是牛人端，将工作信息缓存起来
                [[DDCommunicatedStore sharedStore] storeCommunicatedBoss:job];
                
                //
                [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_CATTLE_COMMUNICATION_EXPECTJOB object:self];
            }
        } failure:^(id responseObject, NSError *error) {
            
        }];
    }
    
}

//  获取对方的详情并缓存起来
- (void)getChatTargetInfo
{
    NSString *userid = nil;
    NSArray *segments = [self.targetId componentsSeparatedByString:@"_"];
    if (segments.count > 0) {
        userid = segments[0];
    }
    if ([DDClientInfoManager clientType] == DDClientTypeBoss) {
        
        NSString *requestUrlString = [[DDAPIGenerate sharedInstance] API:@"employer_loggedin_view_resume"];
        NSDictionary *params = @{@"jobfinder_id": userid};
        
        [[DDNetWorkManager shareManager] POST:requestUrlString parameters:params success:^(id responseObject) {
            
            //  获得一个简历详情
            NSDictionary *data = responseObject[@"data"];
            if (data) {
                
                DDJobfinderDetailInfo *resume = [DDJobfinderDetailInfo yy_modelWithDictionary:data];
                resume.userid = userid;
                [[DDCommunicatedStore sharedStore] storeCommunicatedCattle:resume];
            }
        } failure:^(id responseObject, NSError *error) {
            
        }];
        
    }
}


- (void)setRightBarButtonItemWithWhite
{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setImage:[UIImage imageNamed:@"chat_setting.png"] forState:UIControlStateNormal];
    rightButton.frame = CGRectMake(0, 0, 28, 28);
    [rightButton addTarget: self action: @selector(chatSetting:) forControlEvents: UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarItem;
}

- (void)setChat
{
    self.conversationMessageCollectionView.backgroundColor = COLOR_BACKGROUND;
}

- (void)chatSetting:(id )sender
{
    DDMessageSettingViewController *messageSettingViewController = [[DDMessageSettingViewController alloc] init];
    messageSettingViewController.conversationType = self.conversationType;
    messageSettingViewController.targetId = self.targetId;
    [self.navigationController pushViewController:messageSettingViewController animated:YES];
}

#pragma mark - actions
/// 交换电话号码
- (void)actionChangePhoneButton:(UIButton *)btn
{
    self.popChangePhoneAlert.windowShadowView.hidden = NO;
    self.popChangePhoneAlert.infoLab.text = @"确定交换电话？";
}
- (void)changePhone
{
    if (![[DDContactRequestCache sharedCache] didSendRequest:DDContactRequestPhone withUserId:self.targetId])
    {
        NSDate *currentDate = [NSDate date];//获取当前时间，日期
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        NSString *dateString = [dateFormatter stringFromDate:currentDate];
        
        DDContactRequestMessage *message = [[DDContactRequestMessage alloc] initWithRequestType:DDContactRequestPhone requestAction:DDContactRequestActionRequest];
        message.requestContent = [DDLoginUserManager phone];
        message.changeTime = dateString;
        [self sendMessage:message pushContent:@"对方想要和你交换联系方式"];
    }
    else{
        
        [SVProgressHUD setBackgroundColor:[UIColor whiteColor]];
        [SVProgressHUD showInfoWithStatus:@"已经申请过了"];
    }
}

/// 交换微信
- (void)actionChangeWechat:(UIButton *)btn
{
    
    self.popChangePhoneAlert.windowShadowView.hidden = NO;
    self.popChangePhoneAlert.infoLab.text = @"确定交换微信？";
}
- (void)changeWeiXin
{
    if (![[DDContactRequestCache sharedCache] didSendRequest:DDContactRequestWeixin withUserId:self.targetId])
    {
        NSDate *currentDate = [NSDate date];//获取当前时间，日期
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        NSString *dateString = [dateFormatter stringFromDate:currentDate];
        
        DDContactRequestMessage *message = [[DDContactRequestMessage alloc] initWithRequestType:DDContactRequestWeixin requestAction:DDContactRequestActionRequest];
        
        message.requestContent = ![DDLoginUserManager weixin]?@"未填写":[DDLoginUserManager weixin];
        message.changeTime = dateString;
        [self sendMessage:message pushContent:@"对方想要和你交换联系方式"];
    }
    else{
        
        [SVProgressHUD setBackgroundColor:[UIColor whiteColor]];
        [SVProgressHUD showInfoWithStatus:@"已经申请过了"];
    }
}

#pragma mark - 在线面试   邀约面试
// 在线面试
- (void)actionOnlineVideoInterview:(UIButton *)btn
{
    self.popChangePhoneAlert.windowShadowView.hidden = NO;
    self.popChangePhoneAlert.infoLab.text = @"确定在线面试吗？";
}
- (void)onlineVideoInterview
{
    
    if ([DDClientInfoManager clientType] == DDClientTypeBoss){
        
        /**
         *  Boss端 在线面试  计费查询
         */
        DDBossOnlineInterviewAlert *bossOnlineInterviewAlert = [DDBossOnlineInterviewAlert shareManager];
        bossOnlineInterviewAlert.targetID = self.targetId;
        [bossOnlineInterviewAlert queryInterviewRluesBeforeSelectOnlineInterview];
        
    }else{
    
    RCCall *rcCall = [RCCall sharedRCCall];
    [rcCall startSingleCall:self.targetId mediaType:RCCallMediaVideo];
    }
}

/// 邀约面试
- (void)actionInvitationInterview:(UIButton *)btn
{
    
    self.popChangePhoneAlert.windowShadowView.hidden = NO;
    self.popChangePhoneAlert.infoLab.text = @"确定要和牛人约面试吗？";
}
- (void)invitationInterview
{
    WEAKSELF
    DDInvitedViewController *invitedViewController = [[DDInvitedViewController alloc]init];
    invitedViewController.jobfinderName = !self.title?@"牛人":self.title;
    invitedViewController.jobModel =  weakSelf.bossDetail;
    invitedViewController.job_id = self.jobid;
    invitedViewController.emplyoer_id = [DDLoginUserManager userID];
    
    NSArray *arrayString = [self.targetId componentsSeparatedByString:@"_"]; //从字符_中分隔成2个元素的数组  保存邀请只需要纯数字的id
    invitedViewController.jobfinder_id = [NSString stringWithFormat:@"%@",arrayString[0]];

    [weakSelf.navigationController pushViewController:invitedViewController animated:YES];
    
    
    /**
     *  将面试邀请的内容传过来 并发送自定义消息
     */
    invitedViewController.didGetInterviewMessage = ^(NSInteger interviewType , NSString *interviewID , NSString *interviewTime , NSString *interviewPhone , NSString *interviewAddress , NSString *interviewRemark){
        
        DDInterviewReply *message = [[DDInterviewReply alloc]initWithInterviewReplyType:DDSendInterview InterviewResultType:DDInterviewResultNO];
        NSString *accountName = [DDLoginUserManager accountNamefirst];
        
        NSDictionary *contentDict = @{@"type":@(DDSendInterview),@"result":@(DDInterviewResultNO),@"cattleName":!self.title?@"":self.title,@"bossName":accountName};
        NSData *contentData = [NSJSONSerialization dataWithJSONObject:contentDict options:0 error:nil];
        NSString *contentjson = [[NSString alloc] initWithData:contentData encoding:NSUTF8StringEncoding];
        
        message.content = contentjson;
        message.cattleName = !self.title?@"":self.title;
        message.bossName = accountName;
        [weakSelf sendMessage:message pushContent:@""];

        /**
         发送的第二条自定义消息
         */
        [weakSelf bk_performBlock:^(id obj) {
            
            DDInterviewMessage  *interviewMessage = [[DDInterviewMessage alloc]initWithInterviewType:interviewType];
            
            NSDate *currentDate = [NSDate date];//获取当前时间，日期
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
            NSString *dateString = [dateFormatter stringFromDate:currentDate];
            
            NSDictionary *contentDict2 = @{@"interviewType":@(interviewType),@"interviewId":interviewID,@"interviewTime":interviewTime,@"interViewPhone":interviewPhone,@"interviewAddress":interviewAddress,@"sendTime":dateString};
            NSData *contentData2 = [NSJSONSerialization dataWithJSONObject:contentDict2 options:0 error:nil];
            NSString *contentjson2 = [[NSString alloc] initWithData:contentData2 encoding:NSUTF8StringEncoding];
            
            interviewMessage.content = contentjson2;
            interviewMessage.interviewId = interviewID;
            interviewMessage.interviewTime = interviewTime;
            interviewMessage.interViewPhone = interviewPhone;
            interviewMessage.interviewAddress = interviewAddress;
            interviewMessage.sendTime = dateString;
            [weakSelf sendMessage:interviewMessage pushContent:@"面试邀请"];
            
        } afterDelay:0.5];

    };
}

#pragma mark --- SuperClassMethod

- (void)willDisplayConversationTableCell:(RCMessageBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    if ([cell isKindOfClass:[RCMessageCell class]]) {
        RCMessageCell *messageCell = (RCMessageCell *)cell;
        UIImageView *portraitImageView = (UIImageView *)messageCell.portraitImageView;
        
        portraitImageView.layer.cornerRadius = portraitImageView.width / 2;
        portraitImageView.layer.masksToBounds = YES;
        CGRect rect = portraitImageView.frame;
        
        if (cell.messageDirection == MessageDirection_SEND) {
            rect.origin.y = 0.f;
        } else {
            rect.origin.y = 10.f;
        }
        portraitImageView.frame = rect;  
    }
}

- (void)willDisplayMessageCell:(RCMessageBaseCell *)cell
                   atIndexPath:(NSIndexPath *)indexPath
{
    if ([cell isKindOfClass:[RCTextMessageCell class]]) {
        cell.messageTimeLabel.backgroundColor = [UIColor clearColor];
        cell.messageTimeLabel.textColor = COLOR_FONT_DARK_GRAY;
        
        RCTextMessageCell *textCell = (RCTextMessageCell *)cell;
        
        //      自定义气泡图片的适配
        
        if (cell.messageDirection == MessageDirection_SEND) {
            
            UIImage *image = [UIImage imageNamed:@"对话框2.png"];
            textCell.bubbleBackgroundView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(22,22,10,22)];
        } else{
            
            UIImage *image = [UIImage imageNamed:@"对话框.png"];
            textCell.bubbleBackgroundView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(22,22,10,22)];
        }
    }
    
    if ([cell isKindOfClass:[RCCallDetailMessageCell class]] ) {
        cell.messageTimeLabel.backgroundColor = [UIColor clearColor];
        cell.messageTimeLabel.textColor = COLOR_FONT_DARK_GRAY;
        
        RCCallDetailMessageCell *callCell = (RCCallDetailMessageCell *)cell;
        callCell.bubbleBackgroundView.userInteractionEnabled = NO;
        callCell.mediaTypeIcon.userInteractionEnabled = NO;
        callCell.textLabel.userInteractionEnabled = NO;
        
        //      自定义气泡图片的适配
        
        if (cell.messageDirection == MessageDirection_SEND) {
            
            UIImage *image = [UIImage imageNamed:@"对话框2.png"];
            callCell.bubbleBackgroundView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(22,22,10,22)];
        } else{
            
            UIImage *image = [UIImage imageNamed:@"对话框.png"];
            callCell.bubbleBackgroundView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(22,22,10,22)];
        }
    }
    
    
    if ([cell isKindOfClass:[RCVoiceMessageCell class]] ) {
        cell.messageTimeLabel.backgroundColor = [UIColor clearColor];
        cell.messageTimeLabel.textColor = COLOR_FONT_DARK_GRAY;
        
        RCVoiceMessageCell *callCell = (RCVoiceMessageCell *)cell;
        //      自定义气泡图片的适配
        
        if (cell.messageDirection == MessageDirection_SEND) {
            
            UIImage *image = [UIImage imageNamed:@"对话框2.png"];
            callCell.bubbleBackgroundView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(22,22,10,22)];
        } else{
            
            UIImage *image = [UIImage imageNamed:@"对话框.png"];
            callCell.bubbleBackgroundView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(22,22,10,22)];
        }
    }
}

- (NSString *)cellIdentifierWithMessage:(RCMessageModel *)model andIndexRow:(NSInteger)indexRow
{
    NSString *identifier = @"unknown";
    if ([model.content isKindOfClass:[DDContactRequestMessage class]])
    {
        DDContactRequestMessage *message = (DDContactRequestMessage *)model.content;
        if (message.requestAction == DDContactRequestActionRequest)
        {
            if (model.messageDirection == MessageDirection_SEND)
            {
                identifier= @"DDRequest";
            }
            else
            {
                identifier = @"DDReply";
            }
        }
        else if (message.requestAction == DDContactRequestActionAccept)
        {
            
            if (model.messageDirection == MessageDirection_SEND)
            {
                identifier = @"DDAccept";
            }
            else
            {
                identifier = @"DDAccept_Receive";
            }
        }
        else if (message.requestAction == DDContactRequestActionRefuse)
        {
            identifier = @"DDRefused";
        }
    }
    
    /**
     *  邀约面试相关
     */
    if ([model.content isKindOfClass:[DDInterviewReply class]])
    {
        DDInterviewReply *message = (DDInterviewReply *)model.content;
        
        if (message.interviewReplyType == DDSendInterview) {
            
            identifier = @"DDInterviewTitle";
        }
        if (message.interviewReplyType == DDReplayInterview) {
            
            identifier = @"DDInterviewReplayCell";
        }
        
    }
    
    if ([model.content isKindOfClass:[DDInterviewMessage class]]){
    
        if (model.messageDirection == MessageDirection_SEND){
        
          identifier = @"DDInterviewSendCell";
        }else{
        
         identifier = @"DDInterviewReceiveCell";
        }
    }
    return identifier;
}

//- (RCMessageContent *)willSendMessage:(RCMessageContent *)messageCotent
//{
//    if (![messageCotent isKindOfClass:[RCCommandMessage class]]) {
//        
//        _savaJobIdUserDefaults = [NSUserDefaults standardUserDefaults];
//        [_savaJobIdUserDefaults setObject:[NSString stringWithFormat:@"%@",self.jobid] forKey:[NSString stringWithFormat:@"%@To%@_JobId",self.targetId,self.presentUserID]];
//        [_savaJobIdUserDefaults synchronize];
//        
//        NSDictionary *command = @{@"target":self.presentUserID,@"jobid": self.jobid};
//        NSData *commandData = [NSJSONSerialization dataWithJSONObject:command options:0 error:nil];
//        NSString *commandjson = [[NSString alloc] initWithData:commandData encoding:NSUTF8StringEncoding];
//        RCCommandMessage *commandmsg = [RCCommandMessage messageWithName:@"setjob" data:commandjson];
//        [self sendMessage:commandmsg pushContent:nil];
//    }
//    
//    return messageCotent;
//}

//  在这里，执行缓存是否联系过某人，发送消息后，即与对方联系过
- (void)didSendMessage:(NSInteger)stauts content:(RCMessageContent *)messageCotent
{
    
    if ([messageCotent isKindOfClass:[RCCommandMessage class]] ) {
        
        return;
    }
    
    // 发送过，就说明跟对方聊过天
    [didContactUserdefaults setBool:YES forKey:[NSString stringWithFormat:@"%@To%@",self.presentUserID,self.targetId]];
    [didContactUserdefaults synchronize];
    
    BOOL didCommunicateWithTarget = [[DDCommunicatedStore sharedStore] didChatWithTarget:self.targetId];
    if (!didCommunicateWithTarget) {
        //  缓存是否与对方联系过
        [[DDCommunicatedStore sharedStore] setDidChat:YES withTarget:self.targetId];
        
        //        [[DDCommunicatedStore sharedStore] setJobId:self.jobid withTargetId:self.targetId];
        _savaJobIdUserDefaults = [NSUserDefaults standardUserDefaults];
        [_savaJobIdUserDefaults setObject:[NSString stringWithFormat:@"%@",self.jobid] forKey:[NSString stringWithFormat:@"%@To%@_JobId",self.targetId,self.presentUserID]];
        [_savaJobIdUserDefaults synchronize];
    }
}

/**
 *  处理交换微信  交换电话
 *
 *  @param message <#message description#>
 *  @param accept  <#accept description#>
 */
- (void)dealWithContactRequestMessage:(DDContactRequestMessage *)message accept:(BOOL)accept
{
    
    if (message.changeTime) {
        
        NSUserDefaults *hadChange = [NSUserDefaults standardUserDefaults];
        [hadChange setBool:YES forKey:message.changeTime];
        [hadChange synchronize];
    }
    
    if (accept) {
        
        DDContactRequestMessage *accept = [[DDContactRequestMessage alloc] initWithRequestType:message.requestType requestAction:DDContactRequestActionAccept];
        if (message.requestType == DDContactRequestPhone) {
            
            accept.replyContent = [DDLoginUserManager phone];
            accept.requestContent = message.requestContent;
            
        } else {
            
            accept.replyContent = ![DDLoginUserManager weixin]?@"未填写":[DDLoginUserManager weixin];
            accept.requestContent = message.requestContent;
        }
        
        [self sendMessage:accept pushContent:@"对方同意了您的请求"];
        
    }else{
        
        DDContactRequestMessage *refused = [[DDContactRequestMessage alloc] initWithRequestType:message.requestType requestAction:DDContactRequestActionRefuse];
        if (message.requestType == DDContactRequestPhone) {
            
            refused.replyContent = [DDLoginUserManager phone];
            refused.requestContent = message.requestContent;
        } else {
            
            refused.replyContent = ![DDLoginUserManager weixin]?@"未填写":[DDLoginUserManager weixin];
            refused.requestContent = message.requestContent;
        }
        [self sendMessage:refused pushContent:@"对方拒绝了您的请求"];
    }
    /*
     滚动到列表最下方
     
     @param animated 是否开启动画效果
     */
    [self scrollToBottomAnimated:YES];
}


/**
 *  处理 面试邀请
 *
 *  @param message <#message description#>
 *  @param accept  <#accept description#>
 */
- (void)dealWithRequestInterview:(DDInterviewMessage *)message accept:(BOOL)accept
{
    
    if (message.sendTime) {
        
        NSUserDefaults *hadSendInterview = [NSUserDefaults standardUserDefaults];
        [hadSendInterview setBool:YES forKey:message.sendTime];
        [hadSendInterview synchronize];
    }
    

    if (accept) {
        
        DDInterviewReply *interviewReplyMessage = [[DDInterviewReply alloc]initWithInterviewReplyType:DDReplayInterview InterviewResultType:DDInterviewResultAgree];
       
        NSString *accountName = [DDLoginUserManager accountNamefirst];
        
        NSDictionary *contentDict = @{@"type":@(DDReplayInterview),@"result":@(DDInterviewResultAgree),@"cattleName":accountName,@"bossName":!self.title?@"":self.title};
        NSData *contentData = [NSJSONSerialization dataWithJSONObject:contentDict options:0 error:nil];
        NSString *contentjson = [[NSString alloc] initWithData:contentData encoding:NSUTF8StringEncoding];
        interviewReplyMessage.content = contentjson;
        interviewReplyMessage.cattleName = accountName;
        interviewReplyMessage.bossName = !self.title?@"":self.title;
        [self sendMessage:interviewReplyMessage pushContent:@"同意面试邀请"];
        [self replayInterViewID:message.interviewId withState:@"3"];
        
    }else{
        
        DDInterviewReply *interviewReplyMessage = [[DDInterviewReply alloc]initWithInterviewReplyType:DDReplayInterview InterviewResultType:DDInterviewResultRefuse];

        NSString *accountName = [DDLoginUserManager accountNamefirst];

        NSDictionary *contentDict = @{@"type":@(DDReplayInterview),@"result":@(DDInterviewResultRefuse),@"cattleName":accountName,@"bossName":!self.title?@"":self.title};
        NSData *contentData = [NSJSONSerialization dataWithJSONObject:contentDict options:0 error:nil];
        NSString *contentjson = [[NSString alloc] initWithData:contentData encoding:NSUTF8StringEncoding];
        interviewReplyMessage.content = contentjson;
        interviewReplyMessage.cattleName = accountName;
        interviewReplyMessage.bossName = !self.title?@"":self.title;
        [self sendMessage:interviewReplyMessage pushContent:@"拒绝面试邀请"];
        [self replayInterViewID:message.interviewId withState:@"2"];

    }
    /*
     滚动到列表最下方
     
     @param animated 是否开启动画效果
     */
    [self scrollToBottomAnimated:YES];
}


#pragma mark - 自定义cell设置

-(CGSize)rcConversationCollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    RCMessageModel *model = self.conversationDataRepository[indexPath.row];
    
    if ([model.content isKindOfClass:[DDContactRequestMessage class]]) {
        
        DDContactRequestMessage *message = (DDContactRequestMessage *)model.content;
        
        if (message.requestAction == DDContactRequestActionRequest) {
            
            if (model.messageDirection == MessageDirection_SEND) {
                
                return CGSizeMake(self.view.frame.size.width, 30);
            } else {
                
                return CGSizeMake(self.view.frame.size.width, 140);
            }
        } else {
            
            return CGSizeMake(self.view.frame.size.width, 60);
        }
    }
    
    /**
     *  面试邀约相关
     */
     if ([model.content isKindOfClass:[DDInterviewReply class]])
     {
     
         return CGSizeMake(self.view.frame.size.width, 60);
     }
    
    if ([model.content isKindOfClass:[DDInterviewMessage class]])
    {
        if (model.messageDirection == MessageDirection_SEND){
        
           return CGSizeMake(self.view.frame.size.width, 100);
        }else{
        
            return CGSizeMake(self.view.frame.size.width, 140);
        }
    }
    //返回自定义cell的实际高度
    return CGSizeMake(300, 30);
}

-(RCMessageBaseCell *)rcConversationCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    RCMessageModel *model = self.conversationDataRepository[indexPath.row];
    NSString *cellIndentifier = [self cellIdentifierWithMessage:model andIndexRow:indexPath.row];
    DDContactBaseCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIndentifier forIndexPath:indexPath];
    if ([cell isKindOfClass:[DDContactBaseCell class]]) {
        cell.contactDelegate = self;
        cell.requestInterviewDelegate = self;
    }
    [cell setDataModel:model];
    return cell;
}

-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return self.size;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{    
    WEAKSELF
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        if (!self.headerView) {
            
            self.headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CollectionHeaderIndentifier forIndexPath:indexPath];
            
        }
        
        //headview 数据
        if (self.bossDetail != nil) {
            if ([DDClientInfoManager clientType] == DDClientTypeBoss) {
                
                [self.headerView setResumeInfoLabelWithBossName:@"牛人"];
                
            } else if ([DDClientInfoManager clientType] == DDClientTypeCattle) {
                
                [self.headerView setResumeInfoLabelWithBossName:@"Boss"];
            }
            
            self.headerView.showTips = _showTips;
            
            [self.headerView bk_whenTapped:^{
                
                if (weakSelf.jobid) {
                    
                    DDWorkDetailViewController *vc = [[DDWorkDetailViewController alloc] init];
                    vc.jobDetail = weakSelf.headerView.jobsDetail;
                    
                    if ([DDClientInfoManager clientType] == DDClientTypeBoss) {
                        vc.BossClickByChat = YES;
                    }
                    else {
                        vc.BossClickByChat = NO;
                    }
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }
            }];
            self.headerView.jobsDetail = self.bossDetail;
        }else{
            self.headerView.showTips = NO;
        }
        return self.headerView;
    }
    return nil;
}

#pragma mark --- RCChatSessionInputBarControlDelegate Method

- (RCMessage *)willAppendAndDisplayMessage:(RCMessage *)message
{
    if ([message isKindOfClass:[DDContactRequestMessage class]]) {
        
        DDContactRequestMessage *requestMessage = (DDContactRequestMessage *)message;
        if (requestMessage.requestAction == DDContactRequestActionAccept
            && message.messageDirection == MessageDirection_SEND) {
            
            return nil;
        }
    }
    return message;
}

- (void)didTapCellPortrait:(NSString *)userId
{
    
}

#pragma mark - ddcontact delegate
- (void)didClickPhone:(NSString *)phone
{
    NSString *title = [NSString stringWithFormat:@"%@\n可能是一个电话，你可以", phone];
    [UIAlertView bk_showAlertViewWithTitle:nil
                                   message:title
                         cancelButtonTitle:@"取消"
                         otherButtonTitles:@[@"打电话", @"发短信", @"添加到通讯录"]
                                   handler:^(UIAlertView *alertView, NSInteger buttonIndex)
     {
         switch (buttonIndex) {
             case 1: {
                 NSString *telString = [NSString stringWithFormat:@"tel://%@", phone];
                 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
                 break;
             }
             case 2:{
                 NSString *telString = [NSString stringWithFormat:@"sms://%@", phone];
                 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
                 break;
             }
             case 3:{
                 [self.class CheckAddressBookAuthorization:^(bool isAuthorized) {
                     ABAddressBookRef addBook =ABAddressBookCreateWithOptions(NULL, NULL);;
                     //创建一个联系人引用   设置名字属性
                     NSString *firstName;
                     // 判断是跟Boss 聊天还是跟牛人聊天
                     if ([DDClientInfoManager clientType] == DDClientTypeBoss){
                         firstName = [NSString stringWithFormat:@"牛人-%@",self.title];
                     }else{
                         firstName = [NSString stringWithFormat:@"Boss-%@",self.title];
                     }
                     ABRecordRef person = ABPersonCreate();
                     // 电话号码数组
                     NSArray *phones = [NSArray arrayWithObjects:phone,nil];
                     // 电话号码对应的名称
                     NSArray *labels = [NSArray arrayWithObjects:@"iphone",nil];
                     //这里的字段和上面的字段完全相同
                     // 设置名字属性
                     ABRecordSetValue(person, kABPersonFirstNameProperty,(__bridge CFStringRef)firstName, NULL);
                     // 字典引用
                     ABMultiValueRef dic =ABMultiValueCreateMutable(kABMultiStringPropertyType);
                     // 添加电话号码与其对应的名称内容
                     for (int i = 0; i < [phones count]; i ++) {
                         ABMultiValueIdentifier obj = ABMultiValueAddValueAndLabel(dic,(__bridge CFStringRef)[phones objectAtIndex:i], (__bridge CFStringRef)[labels objectAtIndex:i], &obj);
                     }
                     // 设置phone属性
                     ABRecordSetValue(person, kABPersonPhoneProperty, dic, NULL);
                     // 将新建的联系人添加到通讯录中
                     ABAddressBookAddRecord(addBook, person, NULL);
                     // 保存通讯录数据
                     ABAddressBookSave(addBook, NULL);
                 }];
                 
                 break;
             }
             default:
                 break;
         }
     }];
    
}

- (void)didClickWexin:(NSString *)weixin
{
    if (weixin) {
        [UIPasteboard generalPasteboard].string = weixin;
    }
    [SVProgressHUD setBackgroundColor:[UIColor whiteColor]];
    [SVProgressHUD showInfoWithStatus:@"已复制到剪贴板"];
}

+(void)CheckAddressBookAuthorization:(void (^)(bool isAuthorized))block
{
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
    ABAuthorizationStatus authStatus = ABAddressBookGetAuthorizationStatus();
    
    if (authStatus != kABAuthorizationStatusAuthorized)
    {
        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error)
                                                 {
                                                     dispatch_async(dispatch_get_main_queue(), ^{
                                                         if (error)
                                                         {
                                                             //                                                             NSLog(@"Error: %@", (__bridge NSError *)error);
                                                         }
                                                         else if (!granted)
                                                         {
                                                             
                                                             block(NO);
                                                         }
                                                         else
                                                         {
                                                             block(YES);
                                                         }
                                                     });  
                                                 });  
    }
    else
    {
        block(YES);
    }
}

#pragma mark-回复面试邀请结果
- (void)replayInterViewID:(NSString *)interviewID withState:(NSString *)state
{
  [self.intervitedService replayInterViewID:interviewID withState:state SuccessBlock:^(id responseObject) {
      
  } failBlock:nil];
}

/** 竖直的虚线 */

- (UIImageView *)setupDivideLine_V:(CGFloat)lineHeight
{
    CGPoint beginPoint = CGPointZero;
    CGPoint endPoint = CGPointMake(0, lineHeight);
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 2, lineHeight)];
    UIGraphicsBeginImageContext(imageView.frame.size);   //开始画线
    [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height) blendMode:kCGBlendModeHardLight alpha:1];
    
    CGContextRef lineContext = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(lineContext, UIColor.grayColor.CGColor);
    CGFloat lengths[] = {3, 3};
    CGContextSetLineDash(lineContext, 0, lengths, 2);  //画虚线
    CGContextMoveToPoint(lineContext, beginPoint.x, beginPoint.y);
    CGContextAddLineToPoint(lineContext, endPoint.x, endPoint.y);
    CGContextStrokePath(lineContext);
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    
    return imageView;
}

/*
 滚动到列表最下方
 
 @param animated 是否开启动画效果
 */
- (void)viewDidAppear:(BOOL)animated
{
    
    [self scrollToBottomAnimated:YES];
}

/**
 *  销毁通知
 */
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

@end
